package com.qixiucoding.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * @Description TODO
 * @Author longhj
 * @Date 2021/11/21 星期日 23:43
 */
@Component
public class ResourceTest implements ApplicationContextAware {
    ApplicationContext applicationContext ;

    public Resource getResourceTest() {
        //通过applicationContext，只一步getResource()，就可以获取资源
      return applicationContext.getResource("classpath:config/config.json");
    }
    public Resource getResourceTest2(String addr) {
        //通过applicationContext，只一步getResource()，就可以获取资源
        return applicationContext.getResource(addr);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {

        this.applicationContext = applicationContext;
    }
}
